package com.briup.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;


public class ToolMan {

    public static SqlSession getSqlSession() {
        SqlSession sqlSession = null;
        try {
            String resource = "mybatis-config.xml";
            InputStream resourceAsStream = Resources.getResourceAsStream(resource);
            SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsStream);
            return sqlSession = build.openSession(true);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void close(SqlSession sqlSession) {
        sqlSession.close();
    }
}
